package com.example.receiver;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

public class AudioVoice extends Activity {

	public TextView songName;	
	private ImageButton playButton, pauseButton, stop;
	String namemusic;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.media);

		songName = (TextView) findViewById(R.id.txtView);
		playButton = (ImageButton) findViewById(R.id.imageButton1);
		pauseButton = (ImageButton) findViewById(R.id.imageButton2);
		stop = (ImageButton) findViewById(R.id.imageButton3);

	    namemusic = getIntent().getStringExtra("pathmusic");
		songName.setText("song"+namemusic+".mp3");
		final MediaPlayer mp = new MediaPlayer();
		try {
			mp.setDataSource("/storage/extSdCard/data/" + namemusic + ".mp3");
			mp.prepare();
		} catch (Exception e) {
			e.printStackTrace();
		}

		playButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mp.start();

			}
		});

		pauseButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mp.pause();
			}
		});

		stop.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mp.stop();
				mp.reset();
				try {
					mp.setDataSource("/storage/extSdCard/data/" + namemusic + ".mp3");
					mp.prepare();
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SecurityException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
	}
}
